#import "DDZFModel.h"
#import "DDCouponsModel.h"
#import "DDFSModel.h"
@implementation DDZFModel
DDZFModelManager zfModelManager()
{
    DDZFModelManager manager =
    {
        _getPara,
        _setPara,
        _destroy
    };
    return manager;
};
static DDZFModelPara _para;
static DDZFModelPara _getPara(NSDictionary *dict)
{
    NSArray *keys = [dict allKeys];
    for (NSString *key in keys)
    {
        id value = [dict valueForKey:key];
        
        if ([key isEqualToString:@"coupons"] || [key isEqualToString:@"discoupons"])
        {
            NSMutableArray * array = [NSMutableArray array];
            for (NSDictionary *subDic in value)
            {
                if ([subDic isKindOfClass:[NSDictionary class]])
                {
                    DDCouponsModelPara para = couponsModelManager().getPara(subDic);
                    NSData * data = [[NSData alloc]initWithBytes:&para length:sizeof(para)];
                    [array addObject:data];
                }
            }
            if ([key isEqualToString:@"coupons"]) _para.coupons = array;
            else _para.discoupons = array;
        }
        
        else if ([key isEqualToString:@"paychannels"])
        {
            NSMutableArray * array = [NSMutableArray array];
            for (NSDictionary *subDic in value)
            {
                if ([subDic isKindOfClass:[NSDictionary class]])
                {
//                    DDFSModelPara para = fsModelManager().getPara(subDic);
//                    NSData *data = [[NSData alloc] initWithBytes:&para length:sizeof(para)];
//                    [array addObject:data];
                    [array addObject:subDic];

                }
            }
            _para.fs = array;
        }
        else if ([key isEqualToString:@"vipdiscount"])
        {
            _para.vipdiscount = [NSString stringWithFormat:@"%.1f",[value floatValue] * 0.1];
        }
        else if ([key isEqualToString:@"gamediscount"])
        {
            _para.gamediscount = [NSString stringWithFormat:@"%.1f",[value floatValue] * 0.1];
        }
        else if( [key isEqualToString:@"preorreal"])
        {
            _para.preorreal = [NSString stringWithFormat:@"%@",value];
        }
        else if ([key isEqualToString:@"balance"])
        {
            _para.balance = [NSString stringWithFormat:@"%@",value];
        }
    }
    return _para;
}
static void _setPara(DDZFModelPara para)
{
    _para = para;
}

static DDZFModelPara _destroy(DDZFModelPara para)
{
    para.preorreal = nil;
    para.balance = nil;
    para.vipdiscount = nil;
    para.gamediscount = nil;
    para.coupons = nil;
    para.discoupons = nil;
    para.fs = nil;
    _para = para;
    return para;
};

@end
